var a = function () {
    var tenRmb = new Vue({
        el: "#gd_10rmb_activity",
        data: {
            worldcupImg: [],
            bigImg: [],
            rules: '',
            countdown: 60
        },
        created: function () {
            var _this = this;
            // 获取 静态数据
            $.ajax({
                url: "./data/10rmbData.jsp",
                type: "post",
                dataType: "json",
                async: true,
                success: function (data) {
                    console.log(data);
                    _this.worldcupImg = data.worldcup;
                    _this.bigImg = data.bigfilm;
                    _this.rules = data.gameRule;
                }
            });
            _this.isLogin();
            _this.fc();
        },
        methods: {
           //浮窗在客户端不显示
            fc: function(){
                if(window.isWebView == true){
                     $('.download').css('display', 'none');
                   }
                },
            // 影片点击跳转 app内可以拉起客户端
            bf1: function (e) {
                if (window.isWebView) {
                    $.playDetail(e, 0);
                }
                else {
                    location.href = "http://m.miguvideo.com/wap/resource/migu/openApp/index.html?nodeId=" + e;
                }
            },
            //点击弹出活动规则
            openRule: function () {
                $('.rule, .pop').css('visibility', 'visible');
            },
            //关闭活动规则
            closeRule: function () {
                $('.rule, .pop').css('visibility', 'hidden');
            },
            // 足球详情页跳转 只跳网页
            bf2: function (e) {
                location.href = "http://m.miguvideo.com/wap/resource/migu/openApp/index.html?nodeId=" + e;
            },
            // 判断是否登录
            isLogin: function () {
                var _this = this;
                var islogin = $('#isLogin').val();
                var mobile = $('#mobile').val();
                //    假如没有登陆
                if (islogin == '1') {
                    // 隐藏手机号的中间4位
                    mobile = mobile.substr(0, 3) + '****' + mobile.substr(7);
                    // 此时mphone 的值就是中间四位显示为*号的了； 
                    $('#phoneNum').html(mobile);
                    _this.getUsePhone();
                    $('.wenz').css('display', 'block');
                } else {
                    // 假如没有登录那么让 shuru 这个模块显示出来
                    $('.shuru').css('display', 'block');
                }
            },
            //4g情况下获取电话号码
            getUsePhone: function () {
                util.get4GTel(function (tel) {
                    if (tel) {
                        $('.phoneNum').html(tel);
                    }
                })
            },
            // 点击后判断是带验证码的请求还是不带验证码的请求
            getRegister: function () {
                if ($('.shuru').css('display') == 'block') {
                    //          this.getPrizeRequest();
                    var _this = this;
                    var phoneNumber = $('#phone').val();
                    var smsCode = $('#yangzheng').val();
                    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
                    var testNum = myreg.test(phoneNumber);
                    console.log(phoneNumber);
                    if (phoneNumber == '') {
                        alert("手机号码不能为空！");
                    } else if (phoneNumber.length != 11) {
                        alert("请输入有效的手机号码！");
                    } else if (!testNum) {
                        alert("请输入有效的手机号码！");
                    } else if (phoneNumber.length == 11) {
                        if (smsCode == '') {
                            alert('短信验证码不能为空');
                        } else {
                            _this.getPrizeRequest();
                        }
                    }
                } else {
                    this.getService();
                }
            },
            //  4g 或 已经登录情况下,向后端发起业务请求
            getService: function () {
                var tokenKey = $('#mobile').val();
                var intfId = '15324200556807624050035670370871'; //现网：'15324200556807624050035670370871'
                var signKey = "0ea8b2da-24ec-44eb-82da-c98daeeaff1a", //现网:'0ea8b2da-24ec-44eb-82da-c98daeeaff1a'
                    imei = 10000,
                    idfa = "",
                    res = "",
                    sign = "";
                var s = {
                    "mobile": $('#mobile').val()
                };
                $.ajax({
                    url: "/promactivity/queryAct/getKeyToken",
                    type: "POST",
                    dataType: "JSON",
                    async: true,
                    data: {
                        tokenKey: tokenKey,
                        intfId: intfId
                    },
                    beforeSend: function (jqXHR) { },
                    success: function (data, status, jqXHR) {
                        var code = data.code;
                        if (code == "1014") {
                            if (window.isWebView) {
                                $.startLogin(function (data) {
                                });
                            }
                            else {

                                location.href = "https://passport.migu.cn/login?sourceid=203005&apptype=2&forceAuthn=false&isPassive=false&authType=&display=&callbackURL="
                                    + location.host
                                    + location.pathname
                                    + "&relayState=login"
                            }
                        } else {
                            // res = "userId=" + data.userId + "&intfId=" + intfId + "&imei=" + imei + "&idfa=" + idfa + "&token=" + data.tag + "&signKey=" + signKey;                              
                            res = "userId=&intfId=" + intfId + "&imei=" + imei + "&idfa=" + idfa + "&token=" + data.tag + "&signKey=" + signKey;
                            sign = $.md5(res);
                            console.log(res);
                            console.log(sign)
                            var body = JSON.stringify(s);

                            $.ajax({
                                url: "/promactivity/activityH5/executeH5",
                                type: "POST",
                                dataType: "JSON",
                                async: true,
                                data: {
                                    intfId: intfId,
                                    sign: sign,
                                    imei: 10000,
                                    from: "CMVIDEO",
                                    httpbody: body,
                                    phoneNum: $('#mobile').val()
                                },
                                beforeSend: function (jqXHR) { },
                                success: function (data1, status, jqXHR) {
                                    console.log(data1);
                                    if (data1.code == 1) {
                                        $('.ts1,.pop').css('visibility', 'visible');
                                    } else if (data1.code == 1009) {
                                        $('.ts3,.pop').css('visibility', 'visible');
                                    } else if (data1.code == 1064) {
                                        $('.ts,.pop').css('visibility', 'visible');
                                    } else {
                                        $('.ts2,.pop').css('visibility', 'visible');
                                    }
                                }
                            })
                        }
                    }
                })
            },
            // getService: function () {
            //     var _this = this;
            //     var tokenKey = $('#mobile').val();
            //     var intfId = '15318292030495900111476280986682'; //现网：'15287063832139053747846916130835' 预览："15286836238425414625342243881308"
            //     var signKey = "343a437d-1ccb-4fc0-bc6c-2f0b32cd8d94", //现网：'c3942263-3142-42f3-9bcb-f5caf0616242',预览："3a529fdd-f01f-4be4-92e6-6211875d17c9"
            //         imei = 10000,
            //         idfa = "",
            //         res = "",
            //         sign = "";
            //     var s = {
            //         "mobile": $('#mobile').val()
            //     };
            //     $.ajax({
            //         url: "/promactivity/queryAct/getToken",
            //         type: "POST",
            //         dataType: "JSON",
            //         async: true,
            //         data: {
            //             tokenKey: tokenKey,
            //             intfId: intfId
            //         },
            //         beforeSend: function (jqXHR) { },
            //         success: function (data, status, jqXHR) {
            //             var code = data.code;
            //             if (code == "1014") {
            //                 if (window.isWebView) {
            //                     $.startLogin(function (data) {
            //                     });
            //                 }
            //                 else {
            //                     location.href = "https://passport.migu.cn/login?sourceid=203005&apptype=2&forceAuthn=false&isPassive=false&authType=&display=&callbackURL="
            //                         + location.host
            //                         + location.pathname
            //                         + "&relayState=login"
            //                 }
            //             } else {
            //                 res = "userId=" + data.userId + "&intfId=" + intfId + "&imei=" + imei + "&idfa=" + idfa + "&token=" + data.tag + "&signKey=" + signKey;

            //                 // res = "userId=&intfId=" + intfId + "&imei=" + imei + "&idfa=" + idfa + "&token=" + data.tag + "&signKey=" + signKey;                              
            //                 sign = $.md5(res);
            //                 console.log(res);
            //                 console.log(sign)
            //                 var body = JSON.stringify(s);

            //                 $.ajax({
            //                     url: "/promactivity/activity/execute",
            //                     type: "POST",
            //                     dataType: "JSON",
            //                     async: true,
            //                     data: {
            //                         intfId: intfId,
            //                         sign: sign,
            //                         imei: 10000,
            //                         from: "CMVIDEO",
            //                         httpbody: body,
            //                         phoneNum: $('#mobile').val()
            //                     },
            //                     beforeSend: function (jqXHR) { },
            //                     success: function (data1, status, jqXHR) {
            //                         console.log(data1);
            //                         if (data1.code == 1) {
            //                             $('.ts1,.pop').css('visibility', 'visible');
            //                         } else if (data1.code == 1009) {
            //                             $('.ts3,.pop').css('visibility', 'visible');
            //                         } else if (data1.code == 1064) {
            //                             $('.ts,.pop').css('visibility', 'visible');
            //                         } else {
            //                             $('.ts2,.pop').css('visibility', 'visible');
            //                         }
            //                     }
            //                 })
            //             }
            //         }
            //     })
            // },
            // 获取验证码短信请求
            getmeesageNote: function () {
                var _this = this;
                var fromID = '15324202635904693206734407415536'; //现网:'15324202635904693206734407415536'
                var phoneNum = $('#phone').val();
                var tempCode = '2576217802'; //  预览：'2576217802'
                var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
                var testNum = myreg.test(phoneNum);
                console.log(phoneNum);
                if (phoneNum == '') {
                    alert("手机号码不能为空！");
                } else if (phoneNum.length != 11 && !testNum) {
                    alert("请输入有效的手机号码！");
                } else {
                    $.ajax({
                        url: "/promactivity/sms/sendMsg",
                        type: "post",
                        dataType: "json",
                        async: false,
                        data: {
                            fromID: fromID,
                            phoneNum: phoneNum,
                            tempCode: tempCode
                        },
                        success: function (data) {
                            if (data.code == 1) {
                                $('.yangz').css('display', 'none');
                                $('.yangz2').css('display', 'block');
                                $('.yangz2').html("(" + _this.countdown + ")");
                                var t = setInterval(function () {
                                    _this.countdown--;
                                    if (_this.countdown < 10) {
                                        _this.countdown = '0' + _this.countdown;
                                    }
                                    $('.yangz2').html("(" + _this.countdown + ")");
                                    if (_this.countdown == 00) {
                                        _this.countdown = 60;
                                        clearInterval(t);
                                        $('.yangz').css('display', 'block');
                                        $('.yangz2').css('display', 'none');
                                    }
                                }, 1000)
                            }
                        }
                    });
                }



            },
            // 有短信验证码的时候 发起接口请求
            getPrizeRequest: function () {
                var _this = this;
                var smsCode = $('#yangzheng').val();
                var tokenKey = $('#phone').val();
                var intfId = '15324202635904693206734407415536'; //预览:'15324202635904693206734407415536'
                var signKey = "d6a4d91b-2657-4e74-a01c-febbcc66f4eb", //预览:'d6a4d91b-2657-4e74-a01c-febbcc66f4eb'
                    imei = 10000,
                    idfa = "",
                    res = "",
                    sign = "";
                var s = {
                    "mobile": $('#phone').val()
                };
                $.ajax({
                    url: "/promactivity/queryAct/getKeyToken",
                    type: "POST",
                    dataType: "JSON",
                    async: true,
                    data: {
                        tokenKey: tokenKey,
                        intfId: intfId
                    },
                    beforeSend: function (jqXHR) { },
                    success: function (data, status, jqXHR) {
                        var code = data.code;
                        if (code == "1014") {
                            if (window.isWebView) {
                                $.startLogin(function (data) {
                                });
                            }
                            else {

                                location.href = "https://passport.migu.cn/login?sourceid=203005&apptype=2&forceAuthn=false&isPassive=false&authType=&display=&callbackURL="
                                    + location.host
                                    + location.pathname
                                    + "&relayState=login"
                            }
                        } else {
                            // res = "userId=" + data.userId + "&intfId=" + intfId + "&imei=" + imei + "&idfa=" + idfa + "&token=" + data.tag + "&signKey=" + signKey;                              
                            res = "userId=&intfId=" + intfId + "&imei=" + imei + "&idfa=" + idfa + "&token=" + data.tag + "&signKey=" + signKey;
                            sign = $.md5(res);
                            console.log(res);
                            console.log(sign)
                            var body = JSON.stringify(s);

                            $.ajax({
                                url: "/promactivity/activityH5/executeH5",
                                type: "POST",
                                dataType: "JSON",
                                async: true,
                                data: {
                                    intfId: intfId,
                                    smsCode: smsCode,
                                    sign: sign,
                                    imei: 10000,
                                    from: "CMVIDEO",
                                    httpbody: body,
                                    phoneNum: $('#phone').val()
                                },
                                beforeSend: function (jqXHR) { },
                                success: function (data1, status, jqXHR) {
                                    console.log(data1);
                                    if (data1.code == 1) {
                                        $('.ts1,.pop').css('visibility', 'visible');
                                    } else if (data1.code == 1009) {
                                        $('.ts3,.pop').css('visibility', 'visible');
                                    } else if (data1.code == 1064) {
                                        $('.ts,.pop').css('visibility', 'visible');
                                    } else {
                                        $('.ts2,.pop').css('visibility', 'visible');
                                    }
                                }
                            })
                        }
                    }
                })
            },
            // 关闭弹窗的按钮
            cancel_ts: function () {
                $('.ts,.pop').css('visibility', 'hidden');
                $('#yangzheng').val('');
            },
            cancel_ts1: function () {
                $('.ts1,.pop').css('visibility', 'hidden');
                $('#yangzheng').val('');
            },
            cancel_ts2: function () {
                $('.ts2,.pop').css('visibility', 'hidden');
                $('#yangzheng').val('');
            },
            cancel_ts3: function () {
                $('.ts3,.pop').css('visibility', 'hidden');
                $('#yangzheng').val('');
            }
        },
        mounted: function () {
             var swiper1 = new Swiper('.swi1', {
                slidesPerView: 'auto',
                navigation: {
                  nextEl: '.swiper-button-next',
                  prevEl: '.swiper-button-prev'
                }             
            });
        }
    });

}
$(function () {
    if ($.getUrlParam("platform") == "android" || $.getUrlParam("platform") == "ios") {
        window.isWebView = true;
    }

    if (window.isWebView) {
        window.mnWebMain.init(function () {
            a()
        })
    }
    else {
        a()
    }
})